package com.church.action;

import java.util.Map;

import com.church.base.common.util.ExtData;
import com.church.db.CurriculumList;
import com.church.services.CurriculumListServices;
import com.opensymphony.xwork2.ActionContext;

public class SelectCurriculum extends ChurchActionSupport {
	private CurriculumListServices curriculumListServices;
	private ExtData<CurriculumList> extData;
	private CurriculumList curriculumList;
	private int cuId;
	private boolean response;

	public CurriculumListServices getCurriculumListServices() {
		return curriculumListServices;
	}

	public void setCurriculumListServices(
			CurriculumListServices curriculumListServices) {
		this.curriculumListServices = curriculumListServices;
	}

	public ExtData<CurriculumList> getExtData() {
		return extData;
	}

	public void setExtData(ExtData<CurriculumList> extData) {
		this.extData = extData;
	}

	public int getCuId() {
		return cuId;
	}

	public void setCuId(int cuId) {
		this.cuId = cuId;
	}

	public CurriculumList getCurriculumList() {
		return curriculumList;
	}

	public void setCurriculumList(CurriculumList curriculumList) {
		this.curriculumList = curriculumList;
	}

	public boolean isResponse() {
		return response;
	}

	public void setResponse(boolean response) {
		this.response = response;
	}

	public String getAllCurriculumList() {
		extData = new ExtData<CurriculumList>();
		extData.setSuccess(true);
		extData.setRoot(curriculumListServices.getAllCurriculumList());
		return SUCCESS;
	}

	public String getCurriculumListByCuId() {
		extData = new ExtData<CurriculumList>();
		extData.setSuccess(true);
		extData.setRoot(curriculumListServices.getCurriculumListByCuId(cuId));
		return SUCCESS;
	}

	public String addCurriculumList() {
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		String userName = (String) session.get("USER_NAME");
		if(userName!=null)
		{
			curriculumList = new CurriculumList();
			curriculumList.setCurriculumId(cuId);
			curriculumList.setState("0");
			curriculumList.setUserName(userName);
			response = curriculumListServices.addCurriculumList(curriculumList)
				.equals("success");
		}
		else
		{
			response=false;
		}
		return SUCCESS;
	}

	public String removeCurriculumListById() {
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		String userName = (String) session.get("USER_NAME");
		if(userName!=null)
		{
			response = curriculumListServices.removeCurriculumListById(cuId)
					.equals("success");
		}
		else
		{
			response=false;
		}

		return SUCCESS;
	}
	public String removeCurriculumList() {
		response = curriculumListServices.removeCurriculumListById(curriculumList.getId())
					.equals("success");
		return SUCCESS;
	}
	public String getCurriculumListByUserName() {
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		String userName = (String) session.get("USER_NAME");
		if (userName != null) {
			extData = new ExtData<CurriculumList>();
			extData.setSuccess(true);
			extData.setRoot(curriculumListServices
					.getCurriculumListByUserName(userName));
		}
		return SUCCESS;
	}
}
